<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<input type="text" name="title" id="title" placeholder="主题名称" class="layui-input">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="start_time" placeholder="发布开始时间">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="end_time" placeholder="发布结束时间">
		</div>
		<div class="layui-inline">
			<select id="driver_type" name="driver_type" class="layui-input"lay-filter="activity_model" style="width: 150px;">
				<option value="">司机类型</option>
				<option value="1">快车</option>
				<option value="2">城际</option>
			</select>
		</div>
		<div class="layui-inline">
			<select id="target" name="target" class="layui-input" lay-filter="activity_model" style="width: 150px;">
				<option value="">目标用户</option>
				<option value="0">未认证</option>
				<option value="1">已认证</option>
				<option value="2">审核中</option>
				<option value="3">未通过</option>
				<option value="4">特定用户</option>
			</select>
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
			<button class="layui-btn layui-btn-normal" data-url="{:url('add')}" onclick="add_t(this,'添加活动')">
				添加公告
			</button>
		</div>
	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('index')}', page: true, limit: 10, id:'Notice'}" lay-filter="Notice">
		<thead>
		<tr>
			<th lay-data="{field:'id', width:70,fixed: true, sort: true,align:'center',fixed: true}">ID</th>
			<th lay-data="{field:'title', width:180,align:'center'}">活动标题</th>
			<th lay-data="{field:'main_title', width:180,align:'center'}">主标题</th>
			<th lay-data="{field:'content', width:280,align:'center'}">活动简述</th>
			<th lay-data="{field:'is_top', width:150,align:'center'}">是否置顶</th>
			<th lay-data="{field:'driver_type', width:120,align:'center'}">司机类型</th>
			<th lay-data="{field:'target', width:120,align:'center'}">目标用户</th>
			<th lay-data="{field:'region_name', width:120,align:'center'}">推送省份</th>
			<th lay-data="{field:'region_city', width:120,align:'center'}">推送城市</th>
			<th lay-data="{field:'admin_name', width:80,align:'center'}">操作人</th>
			<th lay-data="{field:'create_time', width:160,align:'center'}">操作时间</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:210, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" style="width: 50px">删除</a>
	</script>
	<script>
		// && d.activity_type !=2
		layui.use(['form','table','laydate'], function () {
			var table = layui.table,form = layui.form,laydate = layui.laydate;
			laydate.render({
				elem: '#start_time' //指定元素
			});

			laydate.render({
				elem: '#end_time' //指定元素
			});
			table.on('tool(Notice)', function (obj) {
				var data = obj.data;
				var id = data.id;
				if (obj.event === 'edit') {
					layer.open({
						type: 2,
						title: '编辑活动',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("edit","id=")}' + id //iframe的url
					});
				}else if (obj.event === 'del') {
					layer.confirm('确定删除吗?',function(index){
						var url = '{:url("del","id=")}' + id
						$.get(url,function(data){
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
								window.location.reload();
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						},'json')
						layer.close(index);
					})
				}
			});

			//搜索
			$('.layui-btn').on('click', function () {
				var title 	= $("#title").val();
				var start_time 		= $("#start_time").val();
				var end_time 		= $("#end_time").val();
				var status		= $("#status").val();
				var driver_type		= $("#driver_type").val();
				var target		= $("#target").val();
				table.reload('Notice', {
					url: 'index', where: {
						"title": title,
						"start_time": start_time,
						"end_time": end_time,
						"status": status,
						"target": target,
						"driver_type": driver_type,
					}
				});
			});
		});
	</script>
</block>
